using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JobSeekers_jobdetails : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["jsCurrentPage"] = Request.ServerVariables.Get("URL")
        + "?" + Request.ServerVariables.Get("QUERY_STRING"); ;
        if (!IsPostBack)
        {            
            try
            {
                string jobID = Request.QueryString.Get("JobID");
                UpdateJobView(jobID);
                string fromPage = Request.QueryString.Get("page");                           
                if (jobID != null && jobID != "")
                {
                    ShowDetails(jobID);
                    if(DetailsView1.Rows[19].Cells[1].Text == "1")
                        Literal1.Text =  
                        "<input type=button "+
                        "value='Apply online' "+
                        "onclick =\"window.open('"+
                        "http://www.huukhang.com/"+
                        "job.aspx?JobId=" + 
                        DetailsView1.Rows[2].Cells[1].Text  
                        + "');\">";
                    txtJobID.Text = jobID;
                    txtCompany.Text = DetailsView1.Rows[0].Cells[1].Text;
                    txtASPXPage.Text = fromPage;
                }
                else
                    Response.Redirect("Search.aspx"); 
                
                Literal1.Text += "  <input type=button "+
                        "value='Back' "+
                        "onclick =\"window.history.go(-1);\">";
            }
            catch (Exception ex)
            {
                litError.Text = ex.Message;
            }
        }
    }
    void ShowDetails(string jobID)
    {
        try
        {
            ControlHelper cls = new ControlHelper("");
            cls.CommandText = "SPViewJobDetails";
            cls.ParameterCollection = new string[1] { "@JobID" };
            cls.ValueCollection = new string[1] { jobID};
            cls.CommandType = CommandType.StoredProcedure;
            cls.InitProperties();
            cls.FillDataTableToDetailsView(this.DetailsView1);
        }
        catch (Exception ex)
        {
            litError.Text = ex.Message;
        }
    }
    void UpdateJobView(string jobID)
    {
        SqlServerProvider sqlServerProvider = new SqlServerProvider("");                
        sqlServerProvider.IncreaseJobView(jobID);
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (Convert.ToString(
                        Session["jsuserid"]) == "")
                Response.Redirect("login.aspx");
            string JobID = DetailsView1.Rows[2].Cells[1].Text;         
            SqlServerProvider sqlServerProvider = new SqlServerProvider();
            sqlServerProvider.SaveJob(
            Convert.ToString(
                        Session["jsuserid"]), JobID);
        }
        catch(Exception ex)
        {
            litError.Text = ex.Message;
        }
    }
}
